<script setup lang="ts">
import { reactive } from 'vue'
import { reqLogin } from '@/apis/user'
import { useUserStore } from '@/stores'
import { useRouter } from 'vue-router'

const router = useRouter()
// defineOptions({ name: 'NewView' })
//
const userStore = useUserStore()
const loginForm = reactive({
  username: '',
  password: ''
})
const handleLogin = async () => {
  const res = await reqLogin(loginForm)
  if (res.code === 200) {
    userStore.setToken(res.data.token!, res.data.menuList!)
    userStore.addMenu(router)
    router.push('/home')
  }
}
</script>

<template>
  <div class="login-view">
    <el-form :model="loginForm" class="login-container">
      <h2>登录</h2>
      <el-form-item>
        <el-input v-model="loginForm.username" placeholder="请输入用户名" />
      </el-form-item>
      <el-form-item>
        <el-input v-model="loginForm.password" type="password" placeholder="请输入密码" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleLogin" class="login-btn">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<style lang="scss" scoped>
.login-view {
  width: 100vw;
  height: 100vh;
  background-image: url('../assets/images/login_bg.jpg');
  background-size: 100%;
  overflow: hidden;

  .login-container {
    width: 400px;
    background-color: #fff;
    border: 1px solid #eaeaea;
    border-radius: 15px;
    padding: 35px 35px 15px 35px;
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.3);
    margin: 250px auto;

    h2 {
      text-align: center;
      margin-bottom: 20px;
      font-size: 24px;
      color: #333;
    }

    :deep(.el-form-item__content) {
      justify-content: center;
    }
  }
}
</style>
